package p.ithorns.framework.logger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.yeauty.standard.ServerEndpointExporter;
import p.ithorns.framework.logger.appender.PipedStreamAppender;

/**
 * LoggerAutoConfiguration
 *
 * 必须要加上@ComponentScan 开启本地包扫描，
 * 或者在使用方的 SpringBootApplication 配置 scanBasePackages
 * 不然会无法加载 LogWebSocketEndpoint
 *
 * @author ithorns
 * @version 1.0.0
 * @date 2023/3/10 15:39
 */
@ComponentScan
@Configuration
public class LoggerAutoConfiguration {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    // 因为在logback中显示定义了appender, 会被容器加载，
    // <appender name="PIPE" class="p.ithorns.framework.logger.appender.PipedStreamAppender">，
    // 所以，这里就不用重复构造了
    // @Bean(initMethod = "start", destroyMethod = "close")
    public PipedStreamAppender pipedStreamLogger() {
        return new PipedStreamAppender();
    }

}